/*
  学习目标：Switch组件、404、重定向
*/
import React from 'react';
import {
  BrowserRouter as Router,
  Route,
  NavLink,
  Switch,
  Redirect,
} from 'react-router-dom';
import './index.css';

export default class App extends React.Component {
  render() {
    return (
      <Router>
        <div>
          <h1>app组件</h1>
          <NavLink to="/home" exact>
            调到home
          </NavLink>
          <br />
          <NavLink to="/my">调到我的音乐</NavLink>
          <br />
          <NavLink to="/friend">调到朋友</NavLink>
          {/* 1. 一般Switch要包住所有的Route组件, 作用: 匹配到第一个就停止匹配 */}
          <Switch>
            {/* 3. 重定向路由,一般写在Switch第一个, 并且加上eaxct */}
            <Redirect from="/" to="/home" exact />
            <Route path="/home" component={Home}></Route>
            <Route path="/home" component={Home}></Route>
            <Route path="/home" component={Home}></Route>
            <Route path="/home" component={Home}></Route>
            <Route path="/my" component={MyMusic}></Route>
            <Route path="/friend" component={Friend}></Route>

            {/* 2. Route不写path,放在Switch中最后一个,表示404页面 */}
            <Route component={NotFount}></Route>
          </Switch>
        </div>
      </Router>
    );
  }
}

function NotFount() {
  return <h1>...404..页面</h1>;
}

function Home() {
  return <h1>我是首页组件</h1>;
}

function MyMusic() {
  return <h1>我是我的音乐件</h1>;
}

function Friend() {
  return <h1>我是朋友组件</h1>;
}
